package com.bd.module.login.server.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import com.bd.framework.pojo.OperatorInfo;
import com.bd.framework.utils.database.CheckConnection;
import com.bd.module.login.server.Operator;

public class OperatorImpl implements Operator {

	public OperatorInfo checkOperInfo(OperatorInfo oper) {
		OperatorInfo operInfo = new OperatorInfo();
		Statement dbStatement = null;
		ResultSet opRs = null;
		String operSql = "SELECT op.opname, op.oppass,op.opcode FROM info_operator op WHERE op.OPCODE =" + "'"+oper.getOpCode()+"'";
		System.out.println(operSql);
		try {
			dbStatement = new CheckConnection().getCheckConnection().createStatement();
			opRs = dbStatement.executeQuery(operSql);
			//是否控制返回条数
			while(opRs.next()){
				operInfo.setOpName(opRs.getString("opname"));
				operInfo.setOpCode(opRs.getString("opcode"));
				operInfo.setOpPass(opRs.getString("oppass"));
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}finally{
			try {
				opRs.close();
				dbStatement.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return operInfo;
	}

	public boolean modifyOperInfo(OperatorInfo operInfo) {
		Statement dbStatement = null; boolean executeFlag = false;
		String operSql = "UPDATE info_operator SET oppass = "+"'"+operInfo.getOpPass()+"'"+" WHERE opcode =" + "'"+operInfo.getOpCode()+"'";
		System.out.println(operSql);
		try {
			dbStatement = new CheckConnection().getCheckConnection().createStatement();
			executeFlag = dbStatement.execute(operSql);
		} catch (SQLException e) {
			e.printStackTrace();
		}finally{
			try {
				dbStatement.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return executeFlag;
	}
}
